package com.partsoft.loader;

import org.tanukisoftware.wrapper.WrapperListener;
import org.tanukisoftware.wrapper.WrapperManager;

public class WrapperLauncher implements WrapperListener {
	
	private ContextLauncher contextLauncher = new ContextLauncher();

	public Integer start(String[] args) {
		Integer result = null;
		try {
			contextLauncher.start(args);
		} catch (Throwable e) {
			result = 1;
		}
		return result;
	}

	public int stop(int exitCode) {
		return 0;
	}

	public void controlEvent(int event) {
		if (event == 202) {
			if (!(WrapperManager.isLaunchedAsService()) || (WrapperManager.isIgnoreUserLogoffs())) {
				WrapperManager.stop(-1);
			}
		} else if (event == 200) {
			contextLauncher.stop();
			WrapperManager.stop(0);
		} else {
			WrapperManager.stop(-1);
		}
	}

	public static void main(String[] args) {
		WrapperManager.start(new WrapperLauncher(), args);
	}


}
